package org.moflon.moca;
import java.io.File;
import org.apache.log4j.BasicConfigurator;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EcorePackage;
import org.moflon.moca.rule.parser.RuleParserAdapter;
import org.moflon.util.eMoflonEMFUtil;

import BoardGame.BoardGameFactory;
import BoardGame.BoardGamePackage;
import BoardGame.RuleBuilder;
import Moca.CodeAdapter;
import Moca.MocaFactory;
import MocaTree.Folder;
import MocaTree.MocaTreePackage;

public class MocaMain 
{

  private static CodeAdapter codeAdapter;

  public static void main(String[] args) 
  {
    BasicConfigurator.configure();

    // Register parsers and unparsers
    codeAdapter = MocaFactory.eINSTANCE.createCodeAdapter();
    codeAdapter.getParser().add(new RuleParserAdapter());
    
    // Perform text-to-tree
    Folder tree = codeAdapter.parse(new File("instances/in/"));

    // Save tree to file
    eMoflonEMFUtil.saveModel(MocaTreePackage.eINSTANCE, tree, "instances/tree.xmi");

    // Perform tree-to-model
    RuleBuilder builder = BoardGameFactory.eINSTANCE.createRuleBuilder();
    EPackage rulePackage = builder.transformFolder(tree, BoardGamePackage.eINSTANCE);
    
    // Save model to file
    eMoflonEMFUtil.saveModel(EcorePackage.eINSTANCE, rulePackage, "../Rules/model/Rules.ecore");
   
  }
}